package org.plants.algo;

import java.util.Random;

public abstract class RandomFilling {
	public static double TOLERANCE = 30.0;
	public static int PRIORITY = 2;
	
	public static boolean isSuitableFigure(int inputPlantsNumber, int poolSize, int lifeDuration) {
		if(inputPlantsNumber >= ((TOLERANCE / 100) * (poolSize * poolSize))) {
			return true;
		}
		else
			return false;
	}
	
	public static String getName() {
		return "RandomFilling";
	}
	
	public static void fillPool(Character[][] pool, int inputPlantsNumber, int poolSize) {
		int availablePlants = inputPlantsNumber;
		for(int i = 0; ((i < poolSize) && (availablePlants > 0)); i++) {
			for (int j = 0; (j < poolSize) && (availablePlants > 0); j++) {
				if (pool[i][j] == 'F') {
					pool[i][j] = '+';
					availablePlants -= 1;
				}
			}
		}
		while (availablePlants > 0) {
			Random ranGenerator = new Random();
			int i = ranGenerator.nextInt(poolSize);
			int j = ranGenerator.nextInt(poolSize);
			if (pool[i][j] != '+') {
				pool[i][j] = '+';
				availablePlants -= 1;
			}
		}
	}
}
